/**
 {{ struct_description }}
 */
public struct {{ name.upper_camel_case }}: Equatable {
    {%- for field in fields %}
    public let {{ field.name.lower_camel_case }}: {{ field.type_info.name }}
    {%- endfor %}

    {% for nested_enum in nested_enums %}
    {{ '\n' + indent(nested_enums[nested_enum], 1) }}
    {% endfor %}

    /**
     Initializes a new `{{ name.upper_camel_case }}`.

     {% if fields|length == 1 %}
     - Parameter {{ fields[0].name.lower_camel_case }}: {{ fields[0].description.rstrip() }}
     {% elif fields|length > 1 %}
     - Parameters:
        {% for field in fields %}
        - {{ field.name.lower_camel_case }}: {{ field.description.rstrip() }}
        {% endfor %}
     {% endif %}
     */
    public init({% for field in fields %}{{ field.name.lower_camel_case }}: {{ field.type_info.name }}{{ ", " if not loop.last }}{% endfor %}) {
        {%- for field in fields %}
        self.{{ field.name.lower_camel_case }} = {{ field.name.lower_camel_case }}
        {%- endfor %}
    }

    internal var rpc{{ name.upper_camel_case }}: {{ package.upper_camel_case.replace('_', '').replace('.', '_') }}_{{ name.upper_camel_case }} {
        var rpc{{ name.upper_camel_case }} = {{ package.upper_camel_case.replace('_', '').replace('.', '_') }}_{{ name.upper_camel_case }}()

        {%- for field in fields %}
        {% if field.type_info.is_repeated %}
            {% if field.type_info.is_primitive %}
        rpc{{ name.upper_camel_case }}.{{ field.name.lower_camel_case }} = {{ field.name.lower_camel_case }}
            {% else %}
        rpc{{ name.upper_camel_case }}.{{ field.name.lower_camel_case }} = {{ field.name.lower_camel_case }}.map{ $0.rpc{{ field.type_info.inner_name }} }
            {% endif %}
        {% else %}
            {% if field.type_info.is_primitive %}
        rpc{{ name.upper_camel_case }}.{{ field.name.lower_camel_case }}{% if field.name.lower_camel_case.startswith("has") %}_p{% endif %} = {{ field.name.lower_camel_case }}
            {% else %}
        rpc{{ name.upper_camel_case }}.{{ field.name.lower_camel_case }} = {{ field.name.lower_camel_case }}.rpc{{ field.type_info.name }}
            {% endif %}
        {% endif %}
        {%- endfor %}

        return rpc{{ name.upper_camel_case }}
    }

    internal static func translateFromRpc(_ rpc{{ name.upper_camel_case }}: {{ package.upper_camel_case.replace('_', '').replace('.', '_') }}_{{ name.upper_camel_case }}) -> {{ name.upper_camel_case }} {
        return {{ name.upper_camel_case }}({% for field in fields %}{{ field.name.lower_camel_case }}: {% if field.type_info.is_repeated %}{%- if field.type_info.is_primitive %}rpc{{ name.upper_camel_case }}.{{ field.name.lower_camel_case }}{%- else %}rpc{{ name.upper_camel_case }}.{{ field.name.lower_camel_case }}.map{ {{ field.type_info.inner_name }}.translateFromRpc($0) }{% endif %}{%- else %}{%- if field.type_info.is_primitive %}rpc{{ name.upper_camel_case }}.{{ field.name.lower_camel_case }}{% if field.name.lower_camel_case.startswith("has") %}_p{% endif %}{% else %}{{ field.type_info.name }}.translateFromRpc(rpc{{ name.upper_camel_case }}.{{ field.name.lower_camel_case }}){% endif %}{% endif %}{{ ", " if not loop.last }}{% endfor %})
    }

    public static func == (lhs: {{ name.upper_camel_case }}, rhs: {{ name.upper_camel_case }}) -> Bool {
        return lhs.{{ fields[0].name.lower_camel_case }} == rhs.{{ fields[0].name.lower_camel_case }}
            {%- for field in fields[1:] %}
            && lhs.{{ field.name.lower_camel_case }} == rhs.{{ field.name.lower_camel_case }}
            {%- endfor %}
    }
}
